|
|
|
|
|
|
|
So clearly an HRESULT is a Long variable. Why would I try to raise an error with an HRESULT value? How does an HRESULT differ from a normal API error code? |
|
|
|
|
|
|
|
|
An HRESULT is a Long error value, but unlike regular API result codes, an HRESULT is defined by COM, the Component Object Model. COM defines a special error code format that is completely separate from the Win32 API error results that you obtain using the Err.LastDllError method. HRESULT error codes are the same values used by Visual Basic and other COM-based applications when dealing with object errors. The Err.Raise statement in the GUIDobject class raises the error "ActiveX Component Can't Create Object". This suggests that there is a problem with the program ID. |
|
|
|
|
|
|
|
|
Another approach to determining the meaning of the HRESULT is to look at its value in hexadecimal. In this case, it's &H800401F3, which corresponds to the constant CO_E_CLASSSTRING found in file api32.txt. The Win32 documentation for the CLSIDFromProgID function states that one possible return value for the function is in fact CO_E_CLASSSTRING, which is described as ''The registered CLSID for the ProgID is invalid." |
|
|
|
|
|
|
|
|
So either the registry is hopelessly corrupt or there is something wrong with the program ID. |
|
|
|
|
|
|
|
|
Let's indulge in some wishful thinking, assume that the registry is not corrupt, and examine what could be wrong with the program ID. |
|
|
|
|
|
|
|
|
The first parameter to the CLSIDFromProgID function is described as an LPCOLESTR. What is an LPOLESTR? The LP indicates a pointer. The C indicates a constant value. You know that an LPSTR is a string, and an LPCSTR is a constant stringone that the API function will not modify. But what kind of string is an OLESTR? |
|
|
|
|
|
|
|
|
The declaration from the wtypes.h file is |
|
|
|
|
|
|
|
|
typedef WCHAR OLECHAR;
typedef /* [string] */ OLECHAR __RPC_FAR *LPOLESTR; |
|
|
|
|
|
|
|
|
An LPOLESTR is a pointer to an OLESTR. An OLESTR is made of up of OLECHAR characters, which are defined as the WCHAR datatype. WCHAR is a wide character. |
|
|
|
|
|
|
|
|
In other words, the string must be Unicode. This is something you might as well get used to when it comes to functions that are part of the OLE subsystem. Unlike general Win32 API functions, which have separate ANSI and Unicode entry points and generally use ANSI strings with ANSI entry points, the OLE functions almost always have a single entry point and accept Unicode string parameters. |
|
|
|
|
|
|
|
|
How should you pass a Unicode string to an API function? |
|
|
|
|
|
|
|
|
The lpszProgId parameter is declared ByVal As Long as shown here. The calling routine needs to pass the address of a Unicode string as a parameter. |
|
|
|
|
|